package com.zx.system.block.controller.system;

import com.zx.core.wrapper.PageWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.system.block.param.DictDataParam;
import com.zx.system.block.service.ISysDictDataService;
import com.zx.system.block.vo.SysDictDataVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.Query;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 系统字典数据 <br>
 * create: 2025-11-18
 * </p>
 *
 * @author zhou xun
 */
@RestController
@RequestMapping("/dict/data")
@RequiredArgsConstructor
public class SysDictDataController {
    private final ISysDictDataService iSysDictDataService;

    /**
     * 分页获取字典数据列表
     *
     * @param dictDataParam 查询参数
     * @return {@link PageWrapper<SysDictDataVO>}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:data:list')")
    @OperateLog(value = "分页获取字典数据列表")
    @PostMapping("/listByPage")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典数据参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Query.class})
    )
    public PageWrapper<SysDictDataVO> listByPage(@RequestBody DictDataParam dictDataParam) {
        return iSysDictDataService.selectDictDataVOListByPage(dictDataParam);
    }

    /**
     * 新增字典数据
     *
     * @param dictDataParam 字典数据信息
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:data:add')")
    @OperateLog(value = "新增字典数据")
    @PostMapping("/addDictData")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典数据参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Create.class})
    )
    public ResponseWrapper addDictData(@RequestBody DictDataParam dictDataParam) {
        return iSysDictDataService.addDictData(dictDataParam);
    }

    /**
     * 编辑字典数据
     *
     * @param dictDataParam 字典数据信息
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:data:edit')")
    @OperateLog(value = "编辑字典数据")
    @PutMapping("/editDictData")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典数据参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Update.class})
    )
    public ResponseWrapper editDictData(@RequestBody DictDataParam dictDataParam) {
        return iSysDictDataService.editDictData(dictDataParam);
    }

    /**
     * 修改字典数据状态
     *
     * @param dictDataParam 字典数据参数
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:data:edit')")
    @OperateLog(value = "修改字典数据状态")
    @PutMapping("/editDictDataStatus")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "字典数据参数", rules = {ValidateRulesEnum.OBJECT}, groups = {StatusUpdate.class})
    )
    public ResponseWrapper editDictDataStatus(@RequestBody DictDataParam dictDataParam) {
        return iSysDictDataService.editDictDataStatus(dictDataParam.getId(), dictDataParam.getStatus());
    }

    /**
     * 删除字典数据
     *
     * @param dictDataId 字典数据Id
     * @return {@link ResponseWrapper}
     * @author zhou xun
     * @since 2025-11-18
     */
    @PreAuthorize("hasAuthority('system:dict:data:remove')")
    @OperateLog(value = "删除字典数据")
    @DeleteMapping("/deleteDictData/{dictDataId}")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "字典数据Id", rules = {ValidateRulesEnum.NOT_NULL}, groups = {Update.class})
    })
    public ResponseWrapper deleteDictData(@PathVariable("dictDataId") String dictDataId) {
        return iSysDictDataService.deleteDictData(dictDataId);
    }
}